import java.util.ArrayList;
import java.util.List;

/**
 * @author LKQ
 * @date 2021/12/22 9:30
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.repeatedStringMatch("abcd", "cdabcdab"));
    }

    public int repeatedStringMatch(String a, String b) {
        int m = a.length(), n = b.length();
        int k = n / m + 2;
        StringBuffer sb = new StringBuffer();
        int ans = -1;
        List<Character> list = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            list.add(a.charAt(i));
        }
        for (int i = 0; i < n; i++) {
            if (!list.contains(b.charAt(i))) {
                return -1;
            }
        }
        for (int i = 1 ; i <= k; i++) {
            sb.append(a);
            String str = sb.toString();
            if (str.length() >= b.length()) {
                for (int j = 0; j <= str.length() - b.length(); j++) {
                    String temp = str.substring(j, j + b.length());
                    if (b.equals(temp)) {
                        ans = i;
                        break;
                    }
                }
            }
            if (ans != -1) {
                break;
            }
        }
        return ans;
     }
}
